<?php

namespace App\Validators\Buz;

use Illuminate\Contracts\Validation\Factory;
use Illuminate\Validation\Rule;
use \Prettus\Validator\Contracts\ValidatorInterface;
use \Prettus\Validator\LaravelValidator;

class ToPayOrderValidator extends LaravelValidator
{

    protected $attributes = [
        'property'  => '账户类型',
        'bk_username' => '收款人姓名',
        'bk_category' => '开户行',
        'bk_account' => '开户银行卡号',
        'city_id' => '开户行所在地',
        'bk_branch' => '开户支行名称',
        'bk_number' => '联行号',
        'remark' => '打款原因(备注)',
        'money' => '打款金额',
        'bk_prov' => '开户行省级',
        'bk_city' => '开户行市级',
    ];

    public function __construct(\Illuminate\Contracts\Validation\Factory $validator)
    {
        parent::__construct($validator);
        $this->rules = [
            'single' => [
                'money' => [
                    'required',
                    'regex:/^([1-9][0-9]{0,14})?(0?\.\d{0,2})?$/'
                ],
                'property' => 'required|in:0,1',
                'bk_username' => 'required|max:150',
                'bk_category' => 'required',
                'bk_account' => 'required|max:30',
                'city_id' => [
                    'required',
                    Rule::exists('province_cities', 'id')->where(function ($query) {
                        $query->where('parent', '<>', 0);
                    }),
                ],
                'bk_branch' => 'required|max:255',
                'bk_number' => 'required_if:property,1|max:50',
                'remark' => 'required|max:500'
            ],
            'batch' => [
                'batch_file' => [
                    'required',
                    'file',
                    'mimetypes:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel'
                ]
            ],
            'reader' => [
                'property' => 'required|in:0,1',
                'bk_username' => 'required|max:150',
                'bk_category' => 'required',
                'bk_account' => 'required|max:30',
                'bk_branch' => 'required|max:255',
                'bk_number' => 'required_if:property,1|max:50',
                'remark' => 'required|max:500',
                'money' => [
                    'required',
                    'regex:/^([1-9][0-9]{0,14})?(0?\.\d{0,2})?$/'
                ],
                'bk_prov' => [
                    'required',
                    Rule::exists('province_cities', 'name')->where(function ($query) {
                        $query->where('parent', 0);
                    }),
                ],
                'bk_city' => [
                    'required',
                    Rule::exists('province_cities', 'name')->where(function ($query) {
                        $query->where('parent', '<>', 0);
                    }),
                ]
            ],
        ];
    }
}
